#ifndef CAMERA_H_
#define CAMERA_H_

// OpenCV includes.
#include <cv.h>
#include <highgui.h>
//#include "framegrabber/v4lcapture.h"
#include <curl/curl.h>

#define CAMERA_SRC_LOCAL 0
#define CAMERA_SRC_REMOTE 1

 using namespace std;
 
 /**
  * \brief a Camera device from which Images in IplImage format can be taken.
  * 
  * This class is implemented using OpenCV functions, as of version 1.0.0. The sequence for using the 
  * camera is:
  * <ul>
  * <li> Create an Instance of the camera.
  * <li> Initialize it with camInit.
  * <li> Now you can query images of it by using queryImage.
  * <li> Before exiting, remember to release the camera with cameraRelease.
  * </ul>
  * Taking into account this order you will have no trouble implementing the library.
  */
class Camera
{

private:

	CURL * conn;
	// Video device
	const char *device;
	
	// Input source
	int source;
	
	//whether is a LOCAL or REMOTE camera. Uses constants CAMERA_SRC_LOCAL and CAMERA_SRC_REMOTE
	int camLocation;

	/**
	 * \brief The camera device as implemented in OpenCV
	 */
	CvCapture *cameraDev;
	/**
	 * \brief id of the Camera being used.
	 */
	int camID;
	
	/**
	 * \brief width of the camera frames.
	 */
	int camWidth;
	
	/**
	 * \brief height of the camera frames.
	 */
	int camHeight;

	/**
	 * \brief Flag indicating wether the camera is On (initialized) or not.
	 */
	bool isOn;
	
	/**
	 * \brief The actual image taken by the camera.
	 */
	IplImage* actualImg;
	
public:

	/**
	 * \brief Constructor 
	 * 
	 * Assigns -1 to camId.
	 */
	Camera();
	
	
	/**
	 * \brief Destructor
	 * 
	 */
	~Camera();
	
	/**
	 * \brief Initializes the Camera
	 * 
	 * Depending on the id, the selected camera will be initialized, if it is recognized by the OS.
	 * The camWidth and camHeight properties are calculated.
	 * 
	 * \param camID Id of the camera to be used.
	 */
	
	void camInit(int camID, char* camSrc,int camWidth,int camHeight);
	
	/**
	 * \brief Returns an image from the camera in IplImage format.
	 */
	IplImage* queryImage();
	
	/**
	 * \return The camWidth property.
	 */
	int getCamWidth();
	
	/**
	 * \return The camHeight property.
	 */
	int getCamHeight();
	
	/**
	 * \brief Releases the resources used by the camera.
	 * 
	 * The resources will be released, only if the camera is On.
	 */
	void cameraRelease();
	
	/**
	 * \brief returns the value of the isOn flag.
	 * 
	 * \return false or true depending on isOn.
	 */ 
	bool isCamOn();
	

};


#endif /*CAMERA_H_*/
